<template>
  <div class="standardmanage">
    <div class="containercontent">
      <div class="selectw100 seachTip">
        <div class="inlineblock verticalmiddle infoitem">
          <div class="inlineblock verticalmiddle">
            名称
          </div>
          <div class="inlineblock verticalmiddle informationItem">
            <el-input style="" v-model="searchName" size="mini" placeholder="标准名称" @keyup.enter.native="readStandard(standarQuery,'search')" clearable></el-input>
          </div>
        </div>
        <div class="inlineblock verticalmiddle infoitem">
          <div class="inlineblock verticalmiddle">
            分类
          </div>
          <div class="inlineblock verticalmiddle informationItem">
            <el-select size="mini" v-model="sampleTypeValue" @change="readStandard(standarQuery,'search')" clearable>
              <el-option v-for="item in sampleSelect.itemList" :key="item.code" :label="item.name" :value="item.code">
              </el-option>
            </el-select>
          </div>
        </div>
        <div class="inlineblock basicRightDistanceA searchIcon">
          <el-button size="mini" @click="readStandard(standarQuery,'search')">搜索</el-button>
          <el-button size="mini" @click="emptySearch">清空</el-button>

        </div>
      </div>
      <div class="separaterowTable">
        <div class="tableTittle">
          <div><span class="fontImpact">1</span><span>评价标准</span></div>
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="addStandard" style="float:right" v-if="userOpernation.add.display">添加标准</el-button>
            <form id="fileForm1" style="display:none">
              <input type="file" name="file" id="file1" @change="upload1">
            </form>

            <el-button type="primary" icon="el-icon-plus" size="mini" @click="chooseStandard" style="float:right;margin-right:10px;" v-if="userOpernation.init.display">选择</el-button>
            <el-button type="primary"  size="mini" @click="importExcel" style="float:right;margin-right:10px;" v-if="userOpernation.add.display">导入</el-button>
            <el-button type="primary" size="mini" @click="downloadTem" style="float:right;margin-right:6px;" v-if="userOpernation.upload.display">下载模板</el-button>

        </div>
        <el-table :data="standardTableDate" style="width: 100%" class="tableCon" size="mini" highlight-current-row @cell-click="rowClick"
          @expand-change="expandChange" ref="standardTable" row-key="id" :expand-row-keys="expands">
          <el-table-column min-width="50px" type="expand">
            <template slot-scope="props" v-if = "reload">
              <el-table :data="standardChildTableDate" style="width: 100%" height="200px" size="mini" highlight-current-row ref="standardChildTable"
                class="childTable">
                <el-table-column label="序号" fixed min-width="50px">
                  <template slot-scope="scope">
                    {{scope.$index + 1}}
                  </template>
                </el-table-column>

                <el-table-column property="name" label="名称" min-width="150px" show-overflow-tooltip>
                </el-table-column>

                <el-table-column property="level" label="等级" min-width="100px">
                </el-table-column>
                <!--<el-table-column property="status" label="子集状态" min-width="120px" :formatter="formatter">
                </el-table-column>-->
                <el-table-column label="操作" min-width="160px">
                  <template slot-scope="scope">
                    <!--父元素的草稿或者驳回的时候可以编辑，复制和删除，否则不能-->
                    <!--<el-button v-if="scope.row.status=='1' && userOpernation.disable.display" type="text" size="mini" @click="isStart(scope.row,'childStandard')">停用</el-button>-->
                    <!--<el-button v-if="scope.row.status=='0' && userOpernation.enable.display" type="text" size="mini" @click="isStart(scope.row,'childStandard')">启用</el-button>-->
                    <!--<el-button v-if="scope.row.isApprove" type="text" size="mini" @click="editStandarChild(scope.row,'review')">审核</el-button>-->
                    <el-button @click="editStandarChild(scope.row,'edit')" type="text" size="mini" v-if="(props.row.status =='2' || props.row.status =='4') && userOpernation.update.display"
                      :disabled="scope.row.source !='' && scope.row.source != undefined ">编辑</el-button>
                    <el-button @click="editStandarChild(scope.row,'openEdit')" type="text" size="mini" v-if="(props.row.status =='1') && userOpernation.openUpdate.display"
                      >编辑</el-button>
                    <el-button type="text" size="mini" @click="editStandarChild(scope.row,'copy')" v-if="(props.row.status =='2' || props.row.status =='4') && userOpernation.add.display">复制</el-button>
                    <el-button @click="editStandarChild(scope.row,'look')" type="text" size="mini" v-if="userOpernation.select.display">详情</el-button>

                    <el-button type="text" size="mini" @click="deletestandard(scope.row,'childStandard')" v-if="userOpernation.delete.display && (props.row.status == 2 || props.row.status == 4)"
                      :disabled="scope.row.source !='' && scope.row.source != undefined ">删除</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </template>
          </el-table-column>
          <el-table-column label="序号" min-width="50px">
            <template slot-scope="scope">
              {{scope.$index+(standarQuery.page - 1) * standarQuery.pageCount + 1}}
            </template>
          </el-table-column>
          <el-table-column property="name" label="名称" min-width="100px" show-overflow-tooltip>
          </el-table-column>
          <!--<el-table-column
                  property="code"
                  label="编号"
                  min-width="120px">
                </el-table-column>-->
          <el-table-column property="version" label="标准号" min-width="80px" show-overflow-tooltip>
          </el-table-column>
          <el-table-column property="type" label="分类" :formatter="standardFormatter" min-width="100px">
          </el-table-column>
          <!--<el-table-column
                  property="sampleType"
                  label="样品类型"
                  :formatter="sampleFormatter"
                  min-width="80px">
                </el-table-column>-->
          <el-table-column property="status" label="状态" min-width="80px" :formatter="formatter">
          </el-table-column>
          <el-table-column property="publishedDate" label="实施日期" min-width="100px" :formatter="formatterDate">
          </el-table-column>
          <el-table-column label="操作" min-width="150px">
            <template slot-scope="scope">
              <!--是草稿或者驳回状态时可以添加子集,编辑，待审核时不可删除-->
              <el-button type="text" size="mini" v-if="(scope.row.status =='2' || scope.row.status =='4') && userOpernation.add.display" @click="addStandarChild(scope.row,'new')">添加</el-button>
              <el-button v-if="scope.row.status=='1' && userOpernation.disable.display " type="text" size="mini" @click="isStart(scope.row,'parentStandard')">停用</el-button>
              <el-button v-if="scope.row.status=='0' && userOpernation.enable.display" type="text" size="mini" @click="isStart(scope.row,'parentStandard')">启用</el-button>
              <el-button v-if="scope.row.isApprove" type="text" size="mini" @click="editStandard(scope.row,'review')">审核</el-button>
              <el-button @click="editStandard(scope.row,'edit')" v-if="(scope.row.status =='2' || scope.row.status =='4') && userOpernation.update.display"
                type="text" size="mini" :disabled="scope.row.source !='' && scope.row.source != undefined ">编辑</el-button>
              <el-button @click="editStandard(scope.row,'look')" type="text" size="mini" v-if="userOpernation.select.display">详情</el-button>
              <el-button type="text" size="mini" v-if="userOpernation.delete.display && scope.row.status !='3'" @click="deletestandard(scope.row,'parentStandard')"
                :disabled="scope.row.source !='' && scope.row.source != undefined ">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="block changepages">
          <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="standarQuery.page" :page-sizes="[20,30,40]"
            :page-size="standarQuery.pageCount" layout="total, sizes, prev, pager, next, jumper" :total="rowNumber">
          </el-pagination>
        </div>
      </div>

    </div>
    <div v-if="standarAddShow" style="height:0;">
      <standar-add :newOrEdit="isNew" :canEdit="iscanEdit" :standardDetail="standardDetail" :allUnit = "allUnit"></standar-add>
    </div>
    <el-dialog :visible.sync="standarChildAddShow" width="70%" height="70%" :show-close='false' :closeOnClickModal='false' class="standardFormDialog">
      <span slot="title" class="dialog-title">
        {{newOrEdit =='new'?'添加':(newOrEdit =='edit' || newOrEdit =='openEdit'?'编辑':(newOrEdit =='copy'?'复制':'查看'))}}标准子集
        <el-button @click="closeStandarChild('standarChildForm')" size="mini" class="popupClose">关闭</el-button>
      </span>
      <el-form label-width="110px" :inline="false" class="demo-form-inline firstForm" :model="standarChildForm" :rules="standarChildRules"
        ref="standarChildForm">
        <el-form-item label="标准名称">
          <el-col :span="22">
            <el-input size="mini" placeholder="标准名称" v-model="standarForm.name" disabled v-if="newOrEdit == 'new'"></el-input>
            <el-input size="mini" placeholder="标准名称" v-model="standarChildForm.standardName" disabled v-if="newOrEdit != 'new'"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="子集名称" prop='name'>
          <el-col :span="22">
            <el-input size="mini" placeholder="标准子集名称" v-model="standarChildForm.name" :disabled="!canEdit"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="等级" prop='level'>
          <el-col :span="22">
            <el-select placeholder="请选择" v-model="standarChildForm.level" size="mini" style="width:100%" :disabled="!canEdit">
              <el-option v-for="item in level" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>

            <!--<el-input size="mini" placeholder="等级" v-model="standarChildForm.level" :disabled="!canEdit"></el-input>-->
          </el-col>
        </el-form-item>
      </el-form>
      <div class="penalrow selectw100">
        <el-tabs style="width:100%;">
          <el-tab-pane label="检测项目">
            <div class="inlineblock verticalmiddle width100">
              <!--<el-button v-if="newOrEdit=='edit' || newOrEdit=='new'" type="primary" size="mini" style="float:right;margin-bottom:5px">上传</el-button>-->
              <el-table :data="standarChildForm.valueBeanList" style="width: 100%;" height = "calc(100% - 30px)" size="mini" >
                <el-table-column label="序号" min-width="50px">
                  <template slot-scope="scope">
                    {{scope.$index+1}}
                  </template>
                </el-table-column>
                <el-table-column property="indexName" label="指标名称" min-width="100px">
                </el-table-column>
                <el-table-column label="低限"  min-width="150px">
                  <el-table-column property="low" label="低限值" min-width="90px">
                    <template slot-scope="scope">
                      <el-input class="deal" oninput="this.value=this.value.replace(/[^0-9.]+/,'');"
                      v-model="scope.row.low" size="mini" :disabled="!canEdit" @blur="changeRange(scope.row.low,scope.row)"></el-input>
                    </template>
                  </el-table-column>
                  <el-table-column property="equalLow" label=">" min-width="55px">
                    <template slot-scope="scope">
                      <el-checkbox v-model="scope.row.equalLow"  :disabled="!canEdit" @change="changeRange($event,scope.row)"></el-checkbox>
                    </template>
                  </el-table-column>

                </el-table-column>
                <el-table-column label="高限"  min-width="150px">
                <el-table-column property="equalHigh" label="<" min-width="55px">
                  <template slot-scope="scope">
                    <el-checkbox v-model="scope.row.equalHigh" :disabled="!canEdit"  @change="changeRange($event,scope.row)"></el-checkbox>
                    <!--<el-input-number v-model="scope.row.equalHigh" size="mini" class="number" :disabled="!canEdit"></el-input-number>-->
                  </template>
                </el-table-column>
                <el-table-column property="high" label="高限值" min-width="90px">
                  <template slot-scope="scope">
                    <el-input  class="deal" v-model="scope.row.high" oninput="this.value=this.value.replace(/[^0-9.]+/,'');" size="mini"
                    :disabled="!canEdit" @blur="changeRange(scope.row.high,scope.row)"></el-input>
                  </template>
                </el-table-column>
                </el-table-column>
                <el-table-column property="value" label="标准值" min-width="90px">
                  <template slot-scope="scope">
                    <el-input  v-model="scope.row.value" size="mini"  :disabled="!canEdit" @blur="changeRange(scope.row.value,scope.row)"></el-input>
                  </template>
                </el-table-column>
                <el-table-column property="unitName" label="单位" min-width="70px">
                </el-table-column>
                <el-table-column property="range" label="限值描述" min-width="120px">
                  <template slot-scope="scope">
                    <el-input v-model="scope.row.range" placeholder="请输入内容" size="mini" :disabled="!canEdit"></el-input>
                  </template>
                </el-table-column>
                <el-table-column property="desc" label="等效标准值" min-width="120px">
                  <template slot-scope="scope">
                    <el-input  v-model="scope.row.desc" size="mini" :disabled="!openEdit"  placeholder="以、隔开" class = "descript"></el-input>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>
      <span slot="footer" class="dialog-footer" v-if="newOrEdit != 'look' && newOrEdit != 'review'">
        <el-button type="primary"  size="mini" @click="subStandarChild('commit')" :disabled="!isRepeat">保存</el-button>
        <!--<el-button type="primary"  size="mini" @click="subStandarChild('commit')" :disabled="!isRepeat">提交</el-button>-->
        <!--<el-button type="primary" @click="subStandarChild('save')" size="mini" v-if="isStatus == '2' || newOrEdit == 'new' || newOrEdit == 'copy'" :disabled="!isRepeat">保存</el-button>-->
        <el-button  size="mini" @click="closeStandarChild('standarChildForm')">取 消</el-button>
      </span>
      <span slot="footer" class="dialog-footer" v-if=" newOrEdit == 'review'">
        <el-button type="primary"  @click="reviewFlowPop" size="mini">审核</el-button>
        <el-button  size="mini" @click="closeStandarChild('standarChildForm')">取 消</el-button>
      </span>
      <!--查看-->
      <div slot="footer" class="user-footer" v-if="newOrEdit == 'look'">
        <span>
          创建人:{{standarChildForm.createBy}}
        </span>
        <span>
          创建时间:{{standarChildForm.createTime}}
        </span>
        <span v-if="standarChildForm.updateBy != undefined">
          修改人：{{standarChildForm.updateBy}}
        </span>
        <span v-if="standarChildForm.updateTime != undefined">
          修改时间：{{standarChildForm.updateTime}}
        </span>
      </div>
    </el-dialog>
    <review-flow :addVisible.sync="reviewFlowShow" :reviewData="reviewData" :procInstType="procInstType" :reviewTitle="reviewTitle"
      @reloadMain="closeRefresh"></review-flow>
    <!--<standar-add :newOrEdit="isNew" :canEdit="iscanEdit" :standardDetail="standardDetail"></standar-add>  -->
    <standard-choose :addVisible.sync="chooseStandardshow" @readStandard="readStandard"></standard-choose>
  </div>
</template>

<script>
  import { mapState } from 'vuex'
  const standarAdd = () => import('./children/standarAdd.vue');
  const standardChoose = () => import('./children/standardChoose.vue');
  const reviewFlow = () =>
		import('../../../common/reviewFlow.vue');




  export default {
    data() {
      return {
        reload: true,
        standarQuery: {
          page: 1, //第几页
          pageCount: 20, //页面得记录条数，
        },
        standardTableDate: [],
        rowNumber: 0,
        sampleTypeValue: '',
        oldRow: null,
        standardChildTableDate: [],
        standarForm: {},
        standarChildForm: {
          name: '',
          status: 2,
          level: '',
          valueBeanList: [],
          value: '',
        },
        standarChildRules: {
          name: [
            { required: true, type: 'string', message: '请填写名称', trigger: 'blur' },
          ],

          level: [
            { required: true, type: 'string', message: '请选择等级', trigger: 'blur' },
          ],
        },
        canEdit: true,
        newOrEdit: 'new',
        standarAddShow: false,
        isNew: 'new',
        iscanEdit: true,
        standardDetail: {},
        activeName: 'first',
        // Ⅰ, Ⅱ , Ⅲ ,Ⅳ ,Ⅴ ,Ⅵ ,Ⅶ ,Ⅷ ,Ⅸ ,Ⅹ
        level: [{
          value: '-',
          label: '-'
        }, {
          value: 'A',
          label: 'A'
        }, {
          value: 'B',
          label: 'B'
        }, {
          value: 'C',
          label: 'C'
        }, {
          value: 'D',
          label: 'D'
        }, {
          value: '一级',
          label: '一级'
        }, {
          value: '二级',
          label: '二级'
        }, {
          value: '三级',
          label: '三级'
        }, {
          value: '四级',
          label: '四级'
        }, {
          value: 'Ⅰ',
          label: 'Ⅰ'
        }, {
          value: 'Ⅱ',
          label: 'Ⅱ'
        }, {
          value: 'Ⅲ',
          label: 'Ⅲ'
        }, {
          value: 'Ⅳ',
          label: 'Ⅳ'
        }, {
          value: 'Ⅴ',
          label: 'Ⅴ'
        }, {
          value: 'Ⅵ',
          label: 'Ⅵ'
        },
        {
          value: 'Ⅶ',
          label: 'Ⅶ'
        }],
        isStatus: '',
        showChildpop: false,
        enableStatusValue: '',
        monitorPointBigTypeValue: '',
        expands: [],// 要展开的行，数值的元素是row的key值
        isRepeat: true,
        addNameShow: false,
        reviewFlowShow: false, //审核流显示
        reviewData: null, //点击行需要审核的信息
        procInstType: 't_standard_level', //审核流要查的表
        reviewTitle: '标准子集',
        chooseStandardshow:false, // 选择标准添加
        openEdit:false, //自己里面的备注是否可编辑
        allUnit:[],

        searchName: '',
        standarChildDetailShow: false,

        standarChildAddShow: false,
        analysisAddShow: false,
        itemStatus: '',
        analysisEditShow: false,
        popupShow: false,
        popupTitle: '',
        fuzhiShow: false,
      }
    },
    computed: {
      ...mapState(['daibanItemShow','daibanItem','enableStatus', 'objectSelect', 'sampleSelect', 'tableHeightC', 'monitorPointBigType', 'sampleType', 'analysisItemTableDate', 'submitType']),
      standarHeight() {
        return ((window.innerHeight - 240))
      },
      tableheight() {
        return ((window.innerHeight - 300) / 2 + 47)
      }
    },
    props: ['userOpernation'],
    components: {
      standarAdd, reviewFlow,standardChoose
    },
    created() {
    	console.log(this.daibanItem)
				if(this.daibanItemShow){
						this.editStandard(this.daibanItem,'review')
					this.$store.commit('passDaibanItemShow', false)
			}
      this.$store.dispatch('dogetDictionary');
      this.readStandard(this.standarQuery);
      this.readAllUnit()
    },

    watch: {
    	daibanItem(newer,older){
    		if(this.daibanItemShow){
    				this.editStandard(this.daibanItem,'review')
						this.$store.commit('passDaibanItemShow', false)
    	}
    	},
      standarQuery: {
        handler(val, oldVal) {
          this.readStandard(this.standarQuery)
        },
        deep: true
      },
    },
    methods: {
      changeRange(val,row){
        let range = this.util.changeRange(val,row)
        this.$set(row,'range',range)
      },
      // 审核流弹框
      reviewFlowPop() {
        this.reviewFlowShow = true;
        this.reviewData = this.standarChildForm;
      },
      // 关闭弹框，刷新页面
      closeRefresh() {
        this.$store.dispatch('getWorkflowList', 0).then(res => {
                this.$notify({
                    showClose: true,
                    message: '操作成功',
                    type: 'success',
                    title:"成功"
                })
            })
        var sendId = { id: this.standarChildForm.fRef, name: this.standarChildForm.standardName }
        this.expandChange(sendId, sendId, 'operate')
        this.closeStandarChild('standarChildForm')

      },
      emptySearch() {
        this.searchName = '';
        this.sampleTypeValue = '';
        this.readStandard(this.standarQuery,'search')
      },
      // 过滤状态
      formatter(row, column, cellValue, index) {
        return this.util.changeStatus({ cellValue: cellValue, list: this.enableStatus })

      },
      // 过滤样品类型
      sampleFormatter(row, column, cellValue, index) {
        return this.util.codeChangeName({ cellValue: cellValue, list: this.objectSelect.itemList })
      },
      // 过滤标准分类
      standardFormatter(row, column, cellValue, index) {
        return this.util.codeChangeName({ cellValue: cellValue, list: this.sampleSelect.itemList })
      },
      formatterDate(row, column, cellValue, index){
        return this.util.formatterDate({ cellValue: cellValue})
      },
       // 搜索单位
      readAllUnit(item) {
        this.allUnit = [];
        this.$http({
          method: 'post',
          apiUrl: '/technology/readLabUnitList.htm',
          params: { ename: item },
          isJson: true
        }).then(res => {
          if (res.code == 0) {
            this.allUnit = res.data;
          }

        })
      },
      readStandard(parp,search) {
        var params = {
          name: this.searchName,
          type: this.sampleTypeValue,
        }
        if (search != undefined) {
						this.standarQuery.page = 1;
						params.page = 1;
						params.pageCount = parp.pageCount;
					} else {
						params.page = parp.page;
						params.pageCount = parp.pageCount;
					}
        this.$http({
          method: 'post',
          apiUrl: '/technology/readStandardList.htm',
          params: params,
          isJson: false,
        }).then(res => {
          if (res.code == 0) {
            res.data.forEach(function (item) {
              item.check = false;
            })
            this.standardTableDate = res.data;
            this.reLoad();  //审核之后重新加载，改变状态，子集按钮跟着变化
            if (!res.pageinfo) {
              this.rowNumber = 0;
            } else if (res.pageinfo && !res.pageinfo.rowNumber) {
              this.rowNumber = 0;
            } else {
              this.rowNumber = res.pageinfo.rowNumber;
            }

          }

        })
      },
      //重载数据
      reLoad(){
          this.reload = false;
         this.$nextTick(()=>{
              this.reload = true;
        })
      },
      rowClick(row, column,cell, event) {
        if (column.label != '操作') {
          this.standarForm = row
          Array.prototype.remove = function (val) {
            let index = this.indexOf(val);
            if (index > -1) {
              this.splice(index, 1);
            }
          };
          if (this.expands.indexOf(row.id) < 0) {
            this.expands = [];
            this.expands.push(row.id);
            this.copeId = null;
            var param = {
              id: row.id
            }
            this.$http({
              apiUrl: '/technology/readStandardLevelList.htm',
              type: 'post',
              params: param,
            }).then(res => {
              if (res.code === 0) {
                this.standardChildTableDate = res.data;

              }
            });
          } else {
            this.expands.remove(row.id);
          }
          delete Array.prototype['remove'];
        }
      },

      //点击一级列表按钮
      expandChange(row, expandedRows, operate) {
        console.log(row, expandedRows, operate)
        if (operate == undefined) {  //点击小三角时operate == undefined  ，operate随意传一个值，不为undefed即可 只刷新展开的能力参数
          console.log(111)
          if (this.expands.indexOf(row.id) < 0) {
            this.expands = [];
            this.expands.push(row.id);
          } else {
            this.expands.pop(row.id);
          }
        }
        this.standarForm = row
        if (expandedRows.length > 1) {
          expandedRows.shift()
        }
        if (this.oldRow && this.oldRow != row) {
          this.oldRow.check = false;
        }
        row.check = !row.check;
        this.oldRow = row;
        this.copeId = null;
        if (row.check) {
          var param = {
            id: row.id
          }
          this.$http({
            apiUrl: '/technology/readStandardLevelList.htm',
            type: 'post',
            params: param,
          }).then(res => {
            if (res.code === 0) {
              this.standardChildTableDate = res.data;
              // console.log(this.standardChildTableDate)

            }
          });
        }

      },
      // 添加评价标准
      addStandard() {
        this.isNew = 'new',
          this.standardDetail = {};
        this.iscanEdit = true;
        this.standarAddShow = true;
      },
      // 编辑评价标准
      editStandard(row, isNew) {
				this.standarAddShow = false;
        this.standardDetail = {};
        this.isNew = isNew;
        if (isNew == 'look' || isNew == 'review') {
          this.iscanEdit = false;
        } else {
          this.iscanEdit = true;
        }

        var url = '/technology/readStandard.htm'
        this.$http({
          method: 'post',
          apiUrl: url,
          params: {
            id: row.id,
          },
          isJson: false,
        }).then(res => {
          if (res.code === 0) {
            this.standarAddShow = true;
            for (var i in res.data) {
              this.standardDetail[i] = res.data[i]
            }
          }
        })
      },
      // 关闭添加标准子集弹框
      closeStandarChild(formName) {
        this.$refs[formName].resetFields();
        this.standarChildAddShow = false;
        this.isRepeat = true;
        this.standarChildForm = {
          name: "",
          status: 2,
          level: '',
          valueBeanList: [],
        };
      },
      chooseStandard(){
        this.chooseStandardshow = true
      },
      // 导入结果按钮
    importExcel() { // 模拟file的点击事件
      document.getElementById("file1").click()
    },
    // 导入文件
    upload1(event) {
      var files = document.getElementById('file1').files[0];

      var formData = new FormData();
      formData.append('file', files)
      this.$axios({
        method: 'post',
        url: '/technology/importExcel.htm',
        data: formData,
        headers: {
          'Content-Type': 'multipart/form-data',
          'token':sessionStorage.getItem('loginAccount')?sessionStorage.getItem('loginAccount'):undefined,
        }
      }).then(res => {
        event.target.value= "";
        if (res.data.code == 0) {
          this.$notify({
            title: '消息',
            message: '导入成功',
            type: 'success'
          })
          this.readStandard(this.standarQuery);
        } else {
          this.$notify({
            title: '消息',
            type: 'warning',
            message: res.data.description,
          })
        }

      })
    },
    downloadTem(){
      var url = "/download/template.htm";
      var template = "standard";
      var module = "sysManage";
      var name = "standard"
      let token = sessionStorage.getItem('loginAccount')?sessionStorage.getItem('loginAccount'):undefined
      window.open(process.env.baseUrl + url + '?template=' + template + '&module=' + module + "&name=" + name + "&token=" + token)
    },
      // 添加标准子集
      addStandarChild(row, isNew) {
        // console.log(row)
        for (var i in row) {
          this.standarForm[i] = row[i]
        }
        // console.log(this.standarForm)
        this.standarChildAddShow = true;
        this.newOrEdit = 'new';
        this.canEdit = true;
        this.openEdit = true
        this.readStandardItemList(row)
      },
      // 添加标准子集时 加载检测项目
      readStandardItemList(row) {
        var params = {
          id: row.id
        }
        this.$http({
          method: 'post',
          apiUrl: '/technology/readStandardItemList.htm',
          params: params,
          isJson: false,
        }).then(res => {
          if (res.code == 0) {
            for (var i in res.data) {
              this.$set(res.data[i], 'equalLow', false)
              this.$set(res.data[i], 'equalHigh', false)
            }

            this.standarChildForm.valueBeanList = res.data;

          }

        })
      },
      // 编辑标准子集
      editStandarChild(row, editOrLook) {
        this.newOrEdit = editOrLook;
        if (editOrLook == 'look' || editOrLook == 'review') {
          this.canEdit = false;
          this.openEdit = false
        } else {
          this.canEdit = true;
          this.openEdit = true
        }
        if(editOrLook == 'openEdit'){
          this.canEdit = false;
          this.openEdit = true
        }
        this.$http({
          method: 'post',
          apiUrl: '/technology/readStandardLevel.htm',
          params: {
            id: row.id,
          },
          isJson: false,
        }).then(res => {
          if (res.code === 0) {
            this.standarChildAddShow = true;
            for (var i in res.data) {
              this.standarChildForm[i] = res.data[i]
            }

            for(var i in res.data.valueBeanList){
              if(res.data.valueBeanList[i].equalHigh !== undefined && res.data.valueBeanList[i].equalHigh !== null && res.data.valueBeanList[i].equalHigh !== ''){
                res.data.valueBeanList[i].equalHigh = !res.data.valueBeanList[i].equalHigh;
              }else{
                this.$set(res.data.valueBeanList[i], 'equalHigh', false)
              }
              if(res.data.valueBeanList[i].equalLow !== undefined && res.data.valueBeanList[i].equalLow !== null && res.data.valueBeanList[i].equalLow !== ''){
                res.data.valueBeanList[i].equalLow = !res.data.valueBeanList[i].equalLow;
              }else{
                this.$set(res.data.valueBeanList[i], 'equalLow', false)
              }
            }


            if (this.standarChildForm.createTime != undefined) {
              this.standarChildForm.createTime = this.standarChildForm.createTime.slice(0, this.standarChildForm.createTime.indexOf("."));
            }
            if (this.standarChildForm.updateTime != undefined) {
              this.standarChildForm.updateTime = this.standarChildForm.updateTime.slice(0, this.standarChildForm.updateTime.indexOf("."));
            }
            this.isStatus = this.standarChildForm.status;
          }

        })
      },
      // 提交标准子集的编辑，新增，复制
      subStandarChild(value) {
        this.$refs.standarChildForm.validate((valid) => { //表单验证
          if (valid) {
            var valueBeanList  = JSON.parse(JSON.stringify(this.standarChildForm.valueBeanList))
            for (var i in valueBeanList) {
              valueBeanList[i].equalHigh = !valueBeanList[i].equalHigh;
              valueBeanList[i].equalLow = !valueBeanList[i].equalLow;
              if(valueBeanList[i].low !== "" && valueBeanList[i].low !== null && valueBeanList[i].low !== undefined
              && valueBeanList[i].high !== "" && valueBeanList[i].high !== null && valueBeanList[i].high !== undefined){
                  if (Number(valueBeanList[i].low) >= Number(valueBeanList[i].high)) {
                    this.$notify({
                      type: 'warning',
                      message: '低限值应小于高限!',
                      title:"警告"
                    })
                    return;
                  }
                }
              }
            if (this.newOrEdit == 'new' || this.newOrEdit == 'copy') {
              var url = '/technology/addStandardLevel.htm';
              var data = {
                fRef: this.standarForm.id,
                name: this.standarChildForm.name,
                level: this.standarChildForm.level,
                flowType: 1, //子集flowType 值为1，用来区分不同审核流用的
                valueBeanList: valueBeanList,
              }

              if (value == 'commit') {
                data.submitType = this.submitType.submitOpen;
              } else {
                data.submitType = this.submitType.submitDraft;
              }
              var sendId = { id: this.standarForm.id, name: this.standarForm.name }
            } else {
              var url = '/technology/updateStandardLevel.htm';
              var data = {
                id: this.standarChildForm.id,
                fRef: this.standarChildForm.fRef,
                name: this.standarChildForm.name,
                level: this.standarChildForm.level,
                flowType: 1,
                valueBeanList:valueBeanList
              }

              if (value == 'commit') {
                data.submitType = this.submitType.submitOpen;
              } else {
                data.submitType = this.submitType.submitDraft;
              }
              var sendId = { id: this.standarChildForm.fRef, name: this.standarChildForm.standardName }
            }

            this.isRepeat = false;
            this.$http({
              method: 'post',
              apiUrl: url,
              params: data,
              isJson: true,
               isLoading:true
            }).then(res => {
              this.isRepeat = true;
              if (res.code == 0) {
                this.$notify({
                  type: 'success',
                  message: '提交成功!',
                  title:"成功"
                });

                this.expandChange(sendId, sendId, 'operate')
                this.closeStandarChild('standarChildForm')
              }

            }).catch(() => {

            });

          } else {
            return false;
          }
        })
      },
      //启用或者停用方法
      isStart(row, isChild) {
        var msg = row.status == 0 ? "启用" : "停用";
        this.$confirm("是否" + msg, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          if (isChild == 'parentStandard') {
            var url = '/technology/updateStandardStatus.htm'
          } else if (isChild == 'childStandard') {
            var url = '/technology/updateStandardLevelStatus.htm'
          }
          this.$http({
            method: 'post',
            apiUrl: url,
            params: {
              id: row.id,
              status: row.status == 0 ? 1 : 0,
            },
            isJson: false,
          }).then(res => {
            if (res.code === 0) {
              if (isChild == 'parentStandard') {
                this.readStandard(this.standarQuery);
              } else if (isChild == 'childStandard') {
                this.expandChange({ id: row.fRef }, { id: row.fRef }, 'operate')
              }

            }

          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消' + msg
          });
        });
      },
      // 删除
      // deleteStandardLevel.htm
      deletestandard(row, isChild) {
        // console.log(row)
        if (isChild == 'parentStandard') {
          var url = '/technology/deleteStandard.htm'
        } else if (isChild == 'childStandard') {
          var url = '/technology/deleteStandardLevel.htm'
        }
        this.$confirm('是否删除', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            method: 'post',
            apiUrl: url,
            params: {
              id: row.id,
            },
            isJson: false,
          }).then(res => {
            if (res.code === 0) {
              this.$message({
                type: 'success',
                message: '删除成功!'
              });
              if (isChild == 'parentStandard') {
                this.readStandard(this.standarQuery);
              } else if (isChild == 'childStandard') {
                this.expandChange({ id: row.fRef }, { id: row.fRef }, 'operate')
              }
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      handleSizeChange(val) {
        this.standarQuery.pageCount = val;
      },
      handleCurrentChange(val) {
        this.standarQuery.page = val;
      },
    }
  }

</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  /*.el-form .el-form-item{
      display:inline-block ;
      width: 50%;
      float: left;
    }*/

  .seachTip .infoitem {
    width: 390px;
  }

  .seachTip .informationItem {
    width: 300px;
    float: none;
    margin-left: 8px;
  }


  .infoitem {
    width: calc((100% - 200px)/3);
  }

  .changepages {
    padding: 5px 0;
  }

  .separaterow {
    margin-top: 10px;
  }
</style>
<style>
  /*.standardForm .el-dialog{
        height: 70%;
    }*/

  .standardFormDialog .el-dialog {
    height: 80%;
    margin-top: 10vh !important;
  }

  .standardFormDialog .el-dialog .el-dialog__footer,
  .standardFormDialog .el-dialog .el-dialog__footer .user-footer {
    height: 45px;
    line-height: 45px;
    padding: 0 20px !important;
  }

  .standardFormDialog .el-dialog .el-dialog__body {
    height: calc(100% - 85px);
    padding: 10px;
  }

  .standardFormDialog .el-dialog .el-dialog__body .el-form.firstForm {
    height: 120px;
  }

  .standardFormDialog .el-dialog .el-dialog__body .el-form.firstForm .el-form-item {
    margin-bottom: 10px;
    float: left;
    width: 49%;
  }

  .standardFormDialog .el-dialog .el-dialog__body .penalrow {
    height: calc(100% - 120px);
    width: 100%
  }

  .standardFormDialog .el-dialog .el-dialog__body .penalrow .el-tabs,
  .standardFormDialog .el-dialog .el-dialog__body .penalrow .el-tabs .el-tab-pane,
  .standardFormDialog .el-dialog .el-dialog__body .penalrow .el-tabs .el-tab-pane .verticalmiddle {
    height: 100%;
  }

  .standardFormDialog .el-dialog .el-dialog__body .penalrow .el-tabs .el-tabs__content {
    height: calc(100% - 25px)
  }
  /*.standardFormDialog .el-dialog .el-dialog__body .el-dialog__footer  .user-footer{
      height:45px;
      line-height: 45px;
    }*/

  .standardFormDialog .number .el-input-number__decrease,
  .standardFormDialog .number .el-input-number__increase {
    display: none;
  }

  .standardFormDialog .number.el-input-number {
    width: 100%;
  }

  .standardFormDialog .number.el-input-number .el-input__inner {
    padding-left: 5px;
    padding-right: 5px;
  }
</style>
<style>
    .descript input::-webkit-input-placeholder { /* WebKit browsers */
      font-size: 10px !important;
    }

    .descript input:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
      font-size: 10px !important;
    }

    .descript input::-moz-placeholder { /* Mozilla Firefox 19+ */
      font-size: 10px !important;
    }

    .descript input:-ms-input-placeholder { /* Internet Explorer 10+ */
      font-size: 10px !important;
    }
</style>
